package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.SkplQuestion;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SkplLabelQuestion;
import com.ruoyi.system.service.ISkplLabelQuestionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 问题标签关系Controller
 *
 * @author ruoyi
 * @date 2022-06-15
 */
@RestController
@RequestMapping("/system/labelquestion")
public class SkplLabelQuestionController extends BaseController
{
    @Autowired
    private ISkplLabelQuestionService skplLabelQuestionService;

    /**
     * 查询问题标签关系列表
     */
    @PreAuthorize("@ss.hasPermi('system:labelquestion:list')")
    @GetMapping("/list")
    public TableDataInfo list(SkplLabelQuestion skplLabelQuestion)
    {
        startPage();
        List<SkplLabelQuestion> list = skplLabelQuestionService.selectSkplLabelQuestionList(skplLabelQuestion);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('system:labelquestion:list')")
    @GetMapping("/listTo/{labelId}")
    public TableDataInfo listTo(@PathVariable("labelId") String labelId)
    {
        startPage();
        List<SkplQuestion> list = skplLabelQuestionService.selectSkplQuestionListByLabelId(labelId);
        return getDataTable(list);
    }
    /**
     * 导出问题标签关系列表
     */
    @PreAuthorize("@ss.hasPermi('system:labelquestion:export')")
    @Log(title = "问题标签关系", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SkplLabelQuestion skplLabelQuestion)
    {
        List<SkplLabelQuestion> list = skplLabelQuestionService.selectSkplLabelQuestionList(skplLabelQuestion);
        ExcelUtil<SkplLabelQuestion> util = new ExcelUtil<SkplLabelQuestion>(SkplLabelQuestion.class);
        util.exportExcel(response, list, "问题标签关系数据");
    }

    /**
     * 获取问题标签关系详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:labelquestion:query')")
    @GetMapping(value = "/{questionId}")
    public AjaxResult getInfo(@PathVariable("questionId") String questionId)
    {
        return AjaxResult.success(skplLabelQuestionService.selectSkplLabelQuestionByQuestionId(questionId));
    }

    /**
     * 新增问题标签关系
     */
    @PreAuthorize("@ss.hasPermi('system:labelquestion:add')")
    @Log(title = "问题标签关系", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SkplLabelQuestion skplLabelQuestion)
    {
        return toAjax(skplLabelQuestionService.insertSkplLabelQuestion(skplLabelQuestion));
    }

    /**
     * 修改问题标签关系
     */
    @PreAuthorize("@ss.hasPermi('system:labelquestion:edit')")
    @Log(title = "问题标签关系", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SkplLabelQuestion skplLabelQuestion)
    {
        return toAjax(skplLabelQuestionService.updateSkplLabelQuestion(skplLabelQuestion));
    }

    /**
     * 删除问题标签关系
     */
    @PreAuthorize("@ss.hasPermi('system:labelquestion:remove')")
    @Log(title = "问题标签关系", businessType = BusinessType.DELETE)
	@DeleteMapping("/{questionIds}")
    public AjaxResult remove(@PathVariable String[] questionIds)
    {
        return toAjax(skplLabelQuestionService.deleteSkplLabelQuestionByQuestionIds(questionIds));
    }
}
